<?php

namespace app\api\model;

use think\Model;

class UserExamination extends Model
{
    public static function getHotList($pageNo, $pageSize)
    {
        $hotList = self::page($pageNo, $pageSize)
            ->group('pid')
            ->field('count(*) as num,pid')
            ->order('num desc')
            ->select()
            ->toArray();
        return array_map(function ($item) {
            $info = ExaminationPaper::getExaminationInfoById($item['pid']);
            return [
                'exam_id' => $item['pid'],
                'exam_title' => $info['title'],
                'cate_title' => $info['category_title'],
                'exam_thumb' => dealImage($info['thumb']),
                'join_number' => $item['num'],
            ];
        }, $hotList);
    }

    public static function countExaminationUser($examinationId)
    {
        return self::where('pid', $examinationId)->count();
    }

    public static function countUserExamination($userId)
    {
        return self::where('uid', $userId)->group('pid')->count();
    }
}